﻿using System;
using System.Text;
using System.Data;
using System.Web.UI.HtmlControls;

namespace LKCMS.Web
{
    public partial class GuestAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                BindMeta("用户咨询留言");
                Bind();

            }
        }

        private void BindMeta(string classname)
        {
            LKCMS.Model.WebSet webset = new LKCMS.BLL.WebSet().loadConfig(LKCMS.Common.Utils.GetXmlMapPath("Configpath"));

            Page.Title = classname + "_" + webset.WebKeywords;


            //Encode/Content type
            HtmlMeta encode = new HtmlMeta();
            encode.HttpEquiv = "Content-Type";
            encode.Content = "text/html; charset=utf-8";
            Page.Header.Controls.Add(encode);

            //Language
            HtmlMeta lang = new HtmlMeta();
            lang.HttpEquiv = "Content-Language";
            lang.Content = "zh-cn";
            Page.Header.Controls.Add(lang);

            //Description
            HtmlMeta desc = new HtmlMeta();
            desc.Name = "Description";
            desc.Content = webset.WebDescription;
            Page.Header.Controls.Add(desc);

            //Keyword
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = webset.WebKeywords;
            Page.Header.Controls.Add(keywords);

        }
        private void Bind()
        {
            StringBuilder sb = new StringBuilder();
            // StringBuilder sb1 = new StringBuilder();
            LKCMS.BLL.Channel bll = new LKCMS.BLL.Channel();
            LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
            LKCMS.Model.Channel model = bll.GetModel(1);


            // DataTable dt = bll.GetListNew(" ParentId=" + model.Id);

            //最近更新
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + model.Title + "</strong>最近更新</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            string s = bll.GetChannels(model.Id).ToString();
            if (s != "")
            {

                DataTable dtzj = pll.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                foreach (DataRow dr1 in dtzj.Rows)
                {
                    sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + dr1["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");

            //最热
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + model.Title + "</strong>热点</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            if (s != "")
            {
                DataTable dtzr = pll.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                foreach (DataRow dr2 in dtzr.Rows)
                {
                    sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + dr2["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");
            this.LiteraClassType.Text = sb.ToString();




        }
        /// <summary>
        /// 遮罩提示窗口
        /// </summary>
        /// <param name="w">宽度</param>
        /// <param name="h">高度</param>
        /// <param name="msgtitle">窗口标题</param>
        /// <param name="msgbox">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        private void JscriptMsg(int w, int h, string msgtitle, string msgbox)
        {
            string msbox = "";
            msbox += "<script src=\"Js/jsmsg.js\" type=\"text/javascript\"></script>\n";
            msbox += "<script type=\"text/javascript\">\n";

            msbox += "alertWin('" + msgtitle + "','" + msgbox + "'," + w + "," + h + ");";
            msbox += "</script>";
            this.Literal1.Text = msbox;
            //  Msg.Text = msbox;
            // Response.End();
        }
        protected void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            if (Session["Code"] != null && Session["Code"].ToString().ToUpper() == txtCode.Text.ToUpper())
            {
                 try
                 {
                     LKCMS.Model.Feedback bmodel = new LKCMS.Model.Feedback();
                     bmodel.AddTime = DateTime.Now;
                     bmodel.Content = LKCMS.Common.Utils.Filter(txtContent.Text);
                     bmodel.IsLock = 0;
                     if (txtUserCome.Text != "")
                     {
                         bmodel.Usercome = LKCMS.Common.Utils.Filter(txtUserCome.Text);
                     }
                     else
                     {
                         bmodel.Usercome = "";
                     }
                     if (txtUserEmail.Text != "")
                     {
                         bmodel.UserEmail = LKCMS.Common.Utils.Filter(txtUserEmail.Text);
                     }
                     else
                     {
                         bmodel.UserEmail = "";
                     }

                     bmodel.UserName = LKCMS.Common.Utils.Filter(this.txtUuserName.Text);
                     if (txtUserTel.Text != "")
                     {
                         bmodel.UserTel = LKCMS.Common.Utils.Filter(txtUserTel.Text);
                     }
                     else
                     {
                         bmodel.UserTel = "";
                     }
                     if (txtQQ.Text != "")
                     {
                         bmodel.UserQQ = LKCMS.Common.Utils.Filter(this.txtQQ.Text);
                     }
                     else
                     {
                         bmodel.UserQQ = "";
                     }
                     bmodel.Content = LKCMS.Common.Utils.Filter(txtContent.Text);
                     bmodel.UserSex = this.ddlSex.SelectedItem.Value;
                     LKCMS.BLL.Feedback bll = new LKCMS.BLL.Feedback();
                     bll.Add(bmodel);
                     JscriptMsg(300, 100, "操作成功", "<div style=\" padding:5px 5px 5px 5px; text-align:left;line-height:24px;\"><b style=\"color:white;\">亲爱访友：</b><br/>&nbsp;&nbsp&nbsp;&nbsp;<span style=\"color:#FBF204;\">已经成功留言！<span/><br/></div>");
                 }
                catch(Exception ex)
                 {
                      JscriptMsg(300, 100, "错误提示", "<div style=\" padding:5px 5px 5px 5px; text-align:left;line-height:24px;\"><b style=\"color:white;\">亲爱访友：</b><br/>&nbsp;&nbsp&nbsp;&nbsp;<span style=\"color:#FBF204;\">"+ex.Message+"<span/><br/></div>");

                }

            }
            else
            {
                JscriptMsg(300, 100, "错误提示", "<div style=\" padding:5px 5px 5px 5px; text-align:left;line-height:24px;\"><b style=\"color:white;\">亲爱访友：</b><br/>&nbsp;&nbsp&nbsp;&nbsp;<span style=\"color:#FBF204;\">输入的验证码不正确。<span/><br/></div>");

            }

        }
    }
}
